package com.ilovepostcard;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.WindowManager;

public class BaseActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        registerExit();
        super.onCreate(savedInstanceState);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); 
    }

    @Override
    protected void onDestroy() {
        unresterExit();
        super.onDestroy();
    }

    private BroadcastReceiver receiver;

    private void registerExit() {
        receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                ((Activity) context).finish();
            }
        };
        IntentFilter filter = new IntentFilter("com.ilovepostcard.Exist");
        registerReceiver(receiver, filter);
    }

    private void unresterExit() {
        try {
            unregisterReceiver(receiver);
        } catch (Throwable t) {

        }
    }
}
